/// Settings Panel ///

using System.Windows.Forms;
using System.Drawing;
using System.Net;
using System.Threading;
using System;

namespace Xyne
{
	public class SettingsPanel : Panel
	{
		private Label nameLabel;
		private TextBox name;
		private Button cancel;
		private Button save;
		private ButtonClicked callback;
		
		public delegate void ButtonClicked();
		
		public ButtonClicked Callback
		{
			get { return callback; }
			set { callback = value; }
		}
		
		public SettingsPanel()
		{
			ConstructControls();
		}
		
		private void ConstructControls()
		{
			SuspendLayout();
			
			int width = 300, height = 0;
			
			nameLabel = new Label();
			nameLabel.Text = "Player Name";
			nameLabel.Location = new Point(5,5);
			Controls.Add(nameLabel);
			height += nameLabel.Size.Height + 5;
			
			name = new TextBox();
			name.Text = Settings.GetSettings().PlayerName;
			name.Location = new Point(5,height);
			name.Size = new Size(width - 15, name.Size.Height);
			Controls.Add(name);
			height += 30;
			
			cancel = new Button();
			cancel.Text = "Cancel";
			cancel.Location = new Point(width - 15 - cancel.Size.Width,height);
			cancel.Click += new EventHandler(CancelClicked);
			Controls.Add(cancel);
			
			save = new Button();
			save.Text = "Save";
			save.Location = new Point(cancel.Location.X - save.Size.Width - 5,height);
			save.Click += new EventHandler(SaveClicked);
			Controls.Add(save);
			height += 30;
			
			height += 30;
			ClientSize = new Size(width, height);
			
			ResumeLayout();
		}
		
		private void CancelClicked(object sender, EventArgs e)
		{
			callback();
		}
		
		private void SaveClicked(object sender, EventArgs e)
		{
			Settings.GetSettings().PlayerName = name.Text;
			Settings.GetSettings().Save();
			
			CancelClicked(sender, e);
		}
	}
}